﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kokomo.Environment;

namespace Kokomo.Environment.Documents
{
	[ViewType(typeof(DetailSurrogateView))]
	public class DetailSurrogateViewModel : NavigationDocumentViewModel
	{
		public DetailSurrogateViewModel(
			Func<object, NavigationContext, DetailViewModel> detailDelegate
			)
			: base()
		{
			if (detailDelegate == null) throw new ArgumentNullException("detailDelegate");

			this.DetailDelegate = detailDelegate;
		}

		public Func<object, NavigationContext, DetailViewModel> DetailDelegate { get; private set; }

		protected override DetailViewModel GetDetailViewModelFor(object obj, NavigationContext navigationContext)
		{
			return this.DetailDelegate(obj, navigationContext);
		}

		protected override void OnCurrentDetailViewModelChanged()
		{
			base.OnCurrentDetailViewModelChanged();

			UiString newHeading =
				(this.CurrentDetailViewModel != null)
				? this.CurrentDetailViewModel.Summary.Heading
				: UntitledDocumentTitle
				;

			this.Title = newHeading;
		}
	}
}
